import { encrypt, decrypt } from './encryption';

export const setStorage = (key: string, value: any) => {
  const serialized = JSON.stringify(value);
  const encrypted = encrypt(serialized);
  uni.setStorageSync(key, encrypted);
};

export const getStorage = (key: string) => {
  const encrypted = uni.getStorageSync(key);
  if (!encrypted) return null;

  try {
    const decrypted = decrypt(encrypted);
    return JSON.parse(decrypted);
  } catch (error) {
    console.error('Decryption failed:', error);
    return null;
  }
};
